package com.xpchenfrank.controller;

import com.xpchenfrank.common.response.RestResponse;
import com.xpchenfrank.entity.WsmReseller;
import com.xpchenfrank.mapper.WsmResellerMapper;
import com.xpchenfrank.service.StockService;
import com.xpchenfrank.utils.JsonUtils;
import com.xpchenfrank.vo.WsmResellerVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @author xpchen
 * @time 2018/3/7 17:50
 * @Description
 * @copyright Wuxi Yazuo ,Ltd.copyright 2015-2025
 */
@Slf4j
@RestController
@RequestMapping("reseller")
public class ResellerController {

    @Resource
    WsmResellerMapper wsmResellerMapper;

    @Resource
    StockService stockService;

    @ResponseBody
    @RequestMapping(value = "/list-by-name", method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RestResponse listByName(String name) {
//        List<WsmResellerVO> resellerVOList = wsmResellerMapper.selectByName(name);
//
//        System.out.println("result is " + JsonUtils.toJson(resellerVOList));
//        System.out.println("先试试吧");
//
//        return JsonUtils.toJson(resellerVOList);

        try {
            stockService.get500pxPics();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return RestResponse.success();
    }

    @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RestResponse save(@RequestBody WsmReseller wsmReseller) {

        wsmResellerMapper.insertSelective(wsmReseller);

        return RestResponse.success();
    }
}
